<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
  <style>
   #body{
      width:500px;
	  height:500px;
	  border:solid 1px black;
   }
  </style>
 </head>
    <div id="body"></div>
	<button id="btn_create">增加</button>
	<button id="btn_delete">删除</button>
 </body>
 <script>
   var body = document.getElementById("body");
   var btn_1 = document.getElementById("btn_create");
   var btn_2 = document.getElementById("btn_delete");
   btn_1.addEventListener("click",function(){
       var child = document.createElement("div");
	   child.setAttribute("class","child");
	   child.setAttribute("onclick","deletes(this)");
	   child.style.width = "50px";
	   child.style.height = "50px";
	   child.style.backgroundColor = "red";
	   body.appendChild(child);
   })
   btn_2.addEventListener("click",function(){
      body.removeChild(body.lastChild);
   })
   function deletes(de){
      var deleteDiv = document.getElementsByClassName("child");
	  for(var i = 0;i < deleteDiv.length;i++){
	      if(deleteDiv[i] == de){
		     body.removeChild(deleteDiv[i]);
		  }
	  }
   }
 </script>
</html>
